package com.imcode;

import java.io.*;

/**
 * 对象序列化
 */
public class ObjectOutputStreamDemo {

    public static void main(String[] args) throws IOException {
        ObjectOutputStream out =
                new ObjectOutputStream(new FileOutputStream("file/student.data"));
        Student student = new Student();
        student.setName("张三");
        student.setSex("男");
        student.setAge(30);

        Teacher teacher = new Teacher("张老师");
        student.setTeacher(teacher);

        out.writeObject(student);
        out.close();
    }
}
